<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>拷贝部分图像并调整大小</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.imagecopyresampled.html">imagecopyresampled</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.imagecreate.html">imagecreate</a></div>
 <div class="up"><a href="ref.image.html">GD and Image 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.imagecopyresized" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">imagecopyresized</h1>
  <p class="verinfo">(PHP 4, PHP 5)</p><p class="refpurpose"><span class="refname">imagecopyresized</span> &mdash; <span class="dc-title">拷贝部分图像并调整大小</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.imagecopyresized-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">bool</span> <span class="methodname"><strong>imagecopyresized</strong></span>
    ( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$dst_image</code></span>
   , <span class="methodparam"><span class="type">resource</span> <code class="parameter">$src_image</code></span>
   , <span class="methodparam"><span class="type">int</span> <code class="parameter">$dst_x</code></span>
   , <span class="methodparam"><span class="type">int</span> <code class="parameter">$dst_y</code></span>
   , <span class="methodparam"><span class="type">int</span> <code class="parameter">$src_x</code></span>
   , <span class="methodparam"><span class="type">int</span> <code class="parameter">$src_y</code></span>
   , <span class="methodparam"><span class="type">int</span> <code class="parameter">$dst_w</code></span>
   , <span class="methodparam"><span class="type">int</span> <code class="parameter">$dst_h</code></span>
   , <span class="methodparam"><span class="type">int</span> <code class="parameter">$src_w</code></span>
   , <span class="methodparam"><span class="type">int</span> <code class="parameter">$src_h</code></span>
   )</div>

   <p class="para rdfs-comment">
   <span class="function"><strong>imagecopyresized()</strong></span>
   将一幅图像中的一块正方形区域拷贝到另一个图像中。<em><code class="parameter">dst_image</code></em>
   和 <em><code class="parameter">src_image</code></em>
   分别是目标图像和源图像的标识符。
  </p>
  <p class="para">
   In other words, <span class="function"><strong>imagecopyresized()</strong></span> will take an 
   rectangular area from <em><code class="parameter">src_image</code></em> of width 
   <em><code class="parameter">src_w</code></em> and height <em><code class="parameter">src_h</code></em> at 
   position (<em><code class="parameter">src_x</code></em>,<em><code class="parameter">src_y</code></em>) 
   and place it in a rectangular area of <em><code class="parameter">dst_image</code></em> 
   of width <em><code class="parameter">dst_w</code></em> and height <em><code class="parameter">dst_h</code></em>
   at position (<em><code class="parameter">dst_x</code></em>,<em><code class="parameter">dst_y</code></em>).
  </p>
   <p class="para">
     如果源和目标的宽度和高度不同，则会进行相应的图像收缩和拉伸。坐标指的是左上角。本函数可用来在同一幅图内部拷贝（如果
   <em><code class="parameter">dst_image</code></em> 和 <em><code class="parameter">src_image</code></em>
   相同的话）区域，但如果区域交迭的话则结果不可预知。
   </p>
 </div>

 <div class="refsect1 parameters" id="refsect1-function.imagecopyresized-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<em><code class="parameter">dst_image</code></em></dt>

     <dd>

      <p class="para">目标图象连接资源。</p>
     </dd>

    
    
     <dt>
<em><code class="parameter">src_image</code></em></dt>

     <dd>

      <p class="para">源图象连接资源。</p>
     </dd>

    
    
     <dt>
<em><code class="parameter">dst_x</code></em></dt>

     <dd>

      <p class="para">
       x-coordinate of destination point.
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">dst_y</code></em></dt>

     <dd>

      <p class="para">
       y-coordinate of destination point.
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">src_x</code></em></dt>

     <dd>

      <p class="para">
       x-coordinate of source point.
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">src_y</code></em></dt>

     <dd>

      <p class="para">
       y-coordinate of source point.
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">dst_w</code></em></dt>

     <dd>

      <p class="para">
       Destination width.
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">dst_h</code></em></dt>

     <dd>

      <p class="para">
       Destination height.
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">src_w</code></em></dt>

     <dd>

      <p class="para">源图象的宽度。</p>
     </dd>

    
    
     <dt>
<em><code class="parameter">src_h</code></em></dt>

     <dd>

      <p class="para">源图象的高度。</p>
     </dd>

    
   </dl>

  </p>
 </div>

 <div class="refsect1 returnvalues" id="refsect1-function.imagecopyresized-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   成功时返回 <strong><code>TRUE</code></strong>， 或者在失败时返回 <strong><code>FALSE</code></strong>。
  </p>
 </div>

 <div class="refsect1 examples" id="refsect1-function.imagecopyresized-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-3136">
    <p><strong>Example #1 Resizing an image</strong></p>
    <div class="example-contents"><p>
     This example will display the image at half size.
    </p></div>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;File&nbsp;and&nbsp;new&nbsp;size<br /></span><span style="color: #0000BB">$filename&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'test.jpg'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$percent&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">0.5</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">//&nbsp;Content&nbsp;type<br /></span><span style="color: #0000BB">header</span><span style="color: #007700">(</span><span style="color: #DD0000">'Content-Type:&nbsp;image/jpeg'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;Get&nbsp;new&nbsp;sizes<br /></span><span style="color: #007700">list(</span><span style="color: #0000BB">$width</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$height</span><span style="color: #007700">)&nbsp;=&nbsp;</span><span style="color: #0000BB">getimagesize</span><span style="color: #007700">(</span><span style="color: #0000BB">$filename</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$newwidth&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$width&nbsp;</span><span style="color: #007700">*&nbsp;</span><span style="color: #0000BB">$percent</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$newheight&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$height&nbsp;</span><span style="color: #007700">*&nbsp;</span><span style="color: #0000BB">$percent</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">//&nbsp;Load<br /></span><span style="color: #0000BB">$thumb&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">imagecreatetruecolor</span><span style="color: #007700">(</span><span style="color: #0000BB">$newwidth</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$newheight</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$source&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">imagecreatefromjpeg</span><span style="color: #007700">(</span><span style="color: #0000BB">$filename</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;Resize<br /></span><span style="color: #0000BB">imagecopyresized</span><span style="color: #007700">(</span><span style="color: #0000BB">$thumb</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$source</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$newwidth</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$newheight</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$width</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$height</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;Output<br /></span><span style="color: #0000BB">imagejpeg</span><span style="color: #007700">(</span><span style="color: #0000BB">$thumb</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程的输出类似于：</p></div>
    <div class="mediaobject">
     
     <div class="imageobject">
      <img src="images/21009b70229598c6a80eef8b45bf282b-imagecopyresized.jpg" alt="Output of example : Resizing an image" width="47" height="25" />
     </div>
    </div>
    <div class="example-contents"><p>
     The image will be output at half size, though better
     quality could be obtained using <span class="function"><a href="function.imagecopyresampled.html" class="function">imagecopyresampled()</a></span>.
    </p></div>
   </div>
  </p>
 </div>

 <div class="refsect1 notes" id="refsect1-function.imagecopyresized-notes">
  <h3 class="title">注释</h3>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
     因为调色板图像限制（255+1 种颜色）有个问题。重采样或过滤图像通常需要多于 255
    种颜色，计算新的被重采样的像素及其颜色时采用了一种近似值。对调色板图像尝试分配一个新颜色时，如果失败我们选择了计算结果最接近（理论上）的颜色。这并不总是视觉上最接近的颜色。这可能会产生怪异的结果，例如空白（或者视觉上是空白）的图像。要跳过这个问题，请使用真彩色图像作为目标图像，例如用
    <span class="function"><a href="function.imagecreatetruecolor.html" class="function">imagecreatetruecolor()</a></span> 创建的。
   </p>
  </p></blockquote>
 </div>

 <div class="refsect1 seealso" id="refsect1-function.imagecopyresized-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <span class="function"><a href="function.imagecopyresampled.html" class="function" rel="rdfs-seeAlso">imagecopyresampled()</a> - 重采样拷贝部分图像并调整大小</span>
  </p>
 </div>

</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.imagecopyresampled.html">imagecopyresampled</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.imagecreate.html">imagecreate</a></div>
 <div class="up"><a href="ref.image.html">GD and Image 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
